//
//  HCNavContentViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/5/24.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCNavContentViewController.h"

#import "HCNavTableViewCell.h"

#import "HCFindNavModel.h"

@interface HCNavContentViewController () <UITableViewDelegate,UITableViewDataSource> {
    HCFindNavModel *model__;
}

@end

@implementation HCNavContentViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//    headerView.hidden = YES;
//    centerView.frame = CGRectMake(0, -34, centerView.frame.size.width, centerView.frame.size.height);

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView_ = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.centerView__.frame.size.width, self.centerView__.frame.size.height)];
    self.tableView_.delegate = self;
    self.tableView_.dataSource = self;
    self.tableView_.rowHeight = 92;
    self.tableView_.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.centerView__ addSubview:self.tableView_];
    
    
    self.tableView_.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        NSLog(@"刷新");
        
        dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5/*延迟执行时间*/ * NSEC_PER_SEC));
        
        dispatch_after(delayTime, dispatch_get_main_queue(), ^{
            if (self.block) {
                self.block(self);
            }
        });
    }];

    
    
    [self.tableView_ registerNib:[UINib nibWithNibName:@"HCNavTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"nav"];
    
    
    
//    centerView.backgroundColor = [UIColor blueColor];
    
    // Do any additional setup after loading the view.
}

-(void)setModel:(id)model {
    model__ = model;
    
    [self.tableView_ reloadData];
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5/*延迟执行时间*/ * NSEC_PER_SEC));
    
    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
        [self.tableView_.mj_header beginRefreshing];
    });


    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (model__) {
        return model__.project_shop.count;
    }else{
        return 0;
    }
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HCNavTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"nav" forIndexPath:indexPath];
    
    if (model__) {
        HCFindNavData *data = model__.project_shop[indexPath.row];
        cell.model = data;
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.callBack) {
        self.callBack(indexPath);
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
